package com.example.huazong.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by huazong on 2021/5/8.
 */

public class SecondActivity extends AppCompatActivity {
    AutoCompleteTextView AT_list;
    CheckBox CBX;
    Button btn_WC;
    Intent intent1;
    EditText edt_name,edt_password;
    String country[]={"阿尔巴尼亚","阿尔及利亚","阿富汗","阿根廷","埃及","爱尔兰","澳大利亚","巴哈马","白俄罗斯","百慕大","巴基斯坦","巴拿马","保加利亚","巴西","冰岛",
            "波兰","朝鲜","丹麦","厄瓜多尔","俄罗斯","法国","芬兰","菲律宾","古巴","韩国","荷兰","哈萨克斯坦","加纳","加拿大","柬埔寨","利比里亚","利比亚","马尔代夫",
            "美国","蒙古","缅甸","秘鲁","摩洛哥","墨西哥","尼日利亚","葡萄牙","日本","瑞典","瑞士","塞尔维亚","苏丹","泰国","乌克兰","西班牙","希腊","新加坡","新西兰",
            "匈牙利","叙利亚","牙买加","伊拉克","伊朗","印度","印度尼西亚","英国","越南","以色列","中国大陆","中国澳门","中国香港","中国台湾","智利","中非共和国"};

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_main);
        AT_list=(AutoCompleteTextView)findViewById(R.id.AT_list);

        CBX=(CheckBox)findViewById(R.id.CBX);

        edt_name=(EditText)findViewById(R.id.edt_name);
        edt_password=(EditText)findViewById(R.id.edt_password);
       btn_WC=(Button)findViewById(R.id.btn_WC);
        btn_WC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String stu=edt_password.getText().toString();
                if (edt_name.length()==0) {
                    Toast.makeText(getApplicationContext(),"用户名不能为空！",Toast.LENGTH_SHORT).show();

                }else if(stu.isEmpty()){
                    Toast.makeText(getApplicationContext(),"亲 请输入密码！",Toast.LENGTH_SHORT).show();
                }else if (stu.length()<6) {
                    Toast.makeText(getApplicationContext(), "密码必须为六位数！", Toast.LENGTH_SHORT).show();
                }else if (!CBX.isChecked()){
                        Toast.makeText(getApplicationContext(),"请先勾选软件与许可协议",Toast.LENGTH_SHORT).show();
                }else{
                    String name1 = edt_name.getText().toString();
                    String password1 = edt_password.getText().toString();
                    intent1 = new Intent(SecondActivity.this, MainActivity.class);
                    intent1.putExtra("用户名",name1);
                    intent1.putExtra("密码",password1);

                    startActivity(intent1);
                }

            }
        });



        ArrayAdapter adapterCountry=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,country);
        AT_list.setAdapter(adapterCountry);


    }

}
